import { createRouter, createWebHistory } from 'vue-router';
import webLayout from '@/components/web/layout.vue';

// 后端路由文件
import adminRoutes from './admin.js';

// 开启历史模式
const routerHistory = createWebHistory();

const router = createRouter({
    history: routerHistory,
    routes: [
        {
            path: '/',  //这个“/”写在哪里很重要，必须写在这里
            component: webLayout,
            children: [
                {
                    path: '',
                    redirect: '/index'
                },
                {
                    path: 'index',
                    name: 'web_index',
                    meta: { title: '首页' },
                    component: () => import('@/views/web/index.vue')
                },
                {
                    path: 'home',
                    name: 'web_home',
                    meta: { title: '主页' },
                    component: () => import('@/views/web/home.vue')
                },
                {
                    path: 'about',
                    name: 'web_about',
                    meta: { title: '关于我们' },
                    component: () => import('@/views/web/about.vue')
                },
                {
                    path: 'video/:id',
                    name: 'web_video_detail',
                    meta: { title: '视频详情' },
                    component: () => import('@/views/web/video/detail.vue')
                },
                {
                    path: 'video',
                    name: 'web_video',
                    meta: { title: '视频' },
                    component: () => import('@/views/web/video/index.vue')
                },
                {
                    path: 'video_scroll',
                    name: 'web_video_scroll',
                    meta: { title: '视频滚动加载更多' },
                    component: () => import('@/views/web/video/index_scroll.vue')
                },
                {
                    path: 'donation/:id',
                    name: 'web_donation_detail',
                    meta: { title: '公益项目详情' },
                    component: () => import('@/views/web/donation/detail.vue')
                },
                {
                    path: 'donation',
                    name: 'web_donation',
                    meta: { title: '公益项目' },
                    component: () => import('@/views/web/donation/index.vue')
                },
                {
                    path: 'my',
                    name: 'web_my',
                    meta: { title: '我的', requireAuth: true },
                    component: () => import('@/views/web/my/index.vue')
                },
            ]
        },
        {
            path: '/login',
            name: 'web_login',
            meta: { title: '登录' },
            component: () => import('@/views/web/login.vue')
        },
        {
            path: '/register',
            name: 'web_register',
            meta: { title: '注册' },
            component: () => import('@/views/web/register.vue')
        },
        {
            path: '/404',
            name: '404',
            meta: { title: '404' },
            component: () => import('@/views/404.vue')
        },
        // {
        //     path: '/admin/:pathMatch(.*)*',
        //     name: 'notFoundAdmin',
        //     component: () => import('@/views/admin/404.vue')
        // },
        {
            path: '/:pathMatch(.*)*',
            name: 'notFound',
            // redirect: '/404',
            meta: { title: '404' },
            component: () => import('@/views/404.vue')
        },
        ...adminRoutes,
    ]
})

// 动态注册路由

// adminLoginRouterStore.getLoginRouter().map((route) => router.addRoute(route))
// adminLoginRouterStore.getLoginRouter().forEach(route => {
//     router.addRoute(route);
// });

export default router
